package cn.example.controller;

import cn.example.pojo.SysRole;
import cn.example.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class HelloController {

    @Autowired
    private SysRoleService sysRoleService;

    @RequestMapping("hello")
    public String hello(){
        System.out.println("2222222");
        System.out.println("asdfghjkl");
        System.out.println("zxcvbnm");
        return "hello";
    }

    @RequestMapping("role")
    @ResponseBody
    public Object rolelist(){
        List<SysRole> sysRole = sysRoleService.getSysRole();
        return sysRole;
    }

    @RequestMapping("addrole")
    @ResponseBody
    public Object addRole(){
        SysRole sysRole = new SysRole();
        sysRole.setCode("004");
        sysRole.setRoleName("abc");
        sysRole.setCreatedUserId(1);
        sysRole.setCreatedTime(new Date());
        int i = sysRoleService.addSysRole(sysRole);
        if(i>0){
            return "success";
        }else{
            return "fail";
        }
    }
}
